﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Semantics;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace GraphBase.Presentation
{
    /// <summary>
    /// 节点数据结构，及确定节点颜色
    /// </summary>
    [Serializable]
    public class NodePos
    {    
        public Node pNode;
        public Point cPoint;
        public String label;
        public NodePos()
        {
        }
        public NodePos(Node node)
        {
            pNode = node;
        }
        public NodePos(int x, int y)
        {
            cPoint.X = x;
            cPoint.Y = y;
        }
        public NodePos(Node node, Point po)
        {
            pNode = node;
            cPoint = po;
            //Id = node.Id;
        }
        public NodePos(Node node, int x, int y)
        {
            pNode = node;
            cPoint.X = x;
            cPoint.Y = y;
        }

        public void DrawColorNodes(Graphics g, string Label, Point cp, int i)
        {
            label = Label;
            Point labelpt = new Point();
            int width = 1;
            if (this.pNode.NodeType == Node.EnumNodeType.SubGraph)
                width = 2;
            Color color = Color.DarkBlue;//默认节点颜色为深蓝色
            switch (i)
            {
                case 0:color=Color.Yellow;//选中节点颜色为黄色
                    break;
                case 1:color=Color.Brown;//选中节点的一个跳度的关联节点颜色为褐色
                    break;
                case 2:color=Color.Red;//选中节点的第二个跳度关联节点颜色为红色
                    break;
                case 3:color=Color.Orange;//选中节点的第三个跳度关联节点颜色为橙色
                    break;
                default://color=Color.DarkBlue;//默认节点颜色为深蓝色
                    break;
            }
            g.DrawEllipse(new Pen(color, width), cp.X, cp.Y, 35, 35);
           // g.DrawEllipse(new Pen(color, width), cp.X, cp.Y, 50, 50);

            labelpt.X = cp.X + 2;// +2;
            labelpt.Y = cp.Y + 10;// +10;
            g.DrawString(Label, new Font("Arial", 9), new SolidBrush(Color.Black), labelpt);//节点上的文字
        }
        int selectedRectangle_X, selectedRectangle_Y;
        float selectedRectangle_Width, selectedRectangle_Height;
        public void DrawSelectedRectangle(Graphics g)
        {
            SizeF size = g.MeasureString(pNode.Label, new Font("Arial", 9));
            Pen pen = new Pen(Color.Gray, 1);
            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
            pen.DashPattern = new float[] { 5, 5 };
            selectedRectangle_X = cPoint.X;
            selectedRectangle_Y = cPoint.Y;
            selectedRectangle_Width = size.Width;
            selectedRectangle_Height = 35;// size.Height;
            g.DrawRectangle(pen, selectedRectangle_X, selectedRectangle_Y, selectedRectangle_Width, selectedRectangle_Height);
        }
        public bool IsInRectangle(MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;
            int x1 = selectedRectangle_X;
            int y1 = selectedRectangle_Y;
            int x2 = (int)(selectedRectangle_Width + x1);
            int y2 = (int)(selectedRectangle_Height + y1);
            if (x1 <= x && x <= x2 && y1 <= y && y <= y2)
                return true;
            else
                return false;
        }


        public override string ToString()
        {
            return this.pNode.ToString()+this.cPoint.ToString();
        }
    }
}
